package controllers;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.ning.http.client.Cookie;

import antlr.collections.List;

import play.mvc.Controller;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class login extends Application {

	private static Connection conexao;
	private static Statement comando;
	
	/***********************************************************************************/
	
	protected static void conectar() throws SQLException {  
	    
		  
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
		}

			conexao = DriverManager.getConnection(  
			        "jdbc:postgresql://localhost:5432/SGRv2",
			        "postgres",
			        "senha");
		
			comando =  conexao.createStatement();

	}

	/***********************************************************************************/
	
	public static void Login() {
		render();
	}
	
	/***********************************************************************************/
	
	public static void Login( String x) {
		render(x);
	}
	
	/***********************************************************************************/
	
	public static void realizarLogin(String login, String senha) throws SQLException {
						
		conectar();
		
		ResultSet cli = comando.executeQuery("select * from pessoa where login = '" + login + "' and senha = '" + senha + "'" );

	int id = 0;
		
		if(cli.next())
		{
			id = (cli.getInt("idusuario"));
		}

		if(id > 0)
		{		
			masterpage.masterpage();
			//bemVindo.bemVindo();
			
		}
		else
		{			
			Login(  "Usuario invalido" );
			
		}	
	}
	
	/***********************************************************************************/
	
	
	
}
